use crate::config::create_data_item_service;
use crate::models;
use models::DataItemsReturn;

#[tauri::command]
pub async fn get_data_by_time_range(
    after: String,
    before: String,
    page: i32,
    name: String,
) -> Result<DataItemsReturn, String> {
    let data_item_service = create_data_item_service();
    let result = match data_item_service
        .get_data_data_items_by_time_range_and_page(&after, &before, page, &name)
    {
        Ok(data) => data,
        Err(e) => {
            return Err(format!("Error: {}", e));
        }
    };
    Ok(result)
}
